package web;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;


public class Topic{
	public static void main(String[] args) throws SQLException{
		

	}
	
	public static List getTopics(int nowpage) throws ClassNotFoundException, SQLException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.getTopics";
	    List l=session.selectList(statement, (nowpage-1)*10);
	    session.close();
		return l;
	}
	public static List getPosts(int tid,int nowpage) throws ClassNotFoundException, SQLException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.getPosts";
		Map<String, Integer> parameterMap = new HashMap<String, Integer>();
	    parameterMap.put("tid", tid);
	    parameterMap.put("nowpage", (nowpage-1)*10);
	    List l=session.selectList(statement, parameterMap);
	    session.close();
		return l;
	}
	
	public static void addTopic(int uid,String theme){
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.addTopic";
		Topics t=new Topics();
		User u=new User();
		u.setUid(uid);
		t.setUser(u);
		t.setTheme(theme);
		
		
		
		int i=session.insert(statement,t);
		
		session.close();
		
		
		
	}
	public static void reply(int uid,int tid,String cont){
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.reply";
		Posts p=new Posts();
		p.setUid(uid);
		p.setTid(tid);
		p.setCont(cont);
		
		session.insert(statement,p);
		session.close();
	}
	public static int getSize() throws ClassNotFoundException, SQLException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.getSize";
	    int s=session.selectOne(statement);
	    session.close();
	    return s;
	}
	public static int getPostSize(int tid) throws ClassNotFoundException, SQLException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.getPostSize";
	    int s=session.selectOne(statement,tid);
	    session.close();
	    return s;
	}
	public static int getMaxTid()throws ClassNotFoundException, SQLException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.getMaxTid";
	    int s=session.selectOne(statement);
	    session.close();
	    return s;
	

	}	
}